<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<head>
    <title>Jumper documentation</title>
    <link rel="stylesheet" href="../ldoc.css" type="text/css" />
</head>
<body>

<div id="container">

<div id="product">
	<div id="product_logo"></div>
	<div id="product_name"><big><b></b></big></div>
	<div id="product_description"></div>
</div> <!-- id="product" -->


<div id="main">


<!-- Menu -->

<div id="navigation">
<br/>
<h1>Jumper</h1>

<ul>
  <li><a href="../index.html">Index</a></li>
</ul>



<h2>Examples</h2>
<ul>
  <li><a href="../examples/annotatedpathing.lua.html">annotatedpathing.lua</a></li>
  <li><strong>customheuristics.lua</strong></li>
  <li><a href="../examples/makeclearance.lua.html">makeclearance.lua</a></li>
  <li><a href="../examples/simpleexample.lua.html">simpleexample.lua</a></li>
</ul>
<h2>Modules</h2>
<ul>
  <li><a href="../modules/core.bheap.html">core.bheap</a></li>
  <li><a href="../modules/core.heuristics.html">core.heuristics</a></li>
  <li><a href="../modules/core.node.html">core.node</a></li>
  <li><a href="../modules/core.path.html">core.path</a></li>
  <li><a href="../modules/grid.html">grid</a></li>
  <li><a href="../modules/pathfinder.html">pathfinder</a></li>
</ul>

</div>

<div id="content">

<h1>Example <code>customheuristics.lua</code></h1>

    <pre>
<span class="comment">--- Example of use for Heuristics
</span>
<span class="keyword">local</span> Grid = <span class="global">require</span> (<span class="string">"jumper.grid"</span>)
<span class="keyword">local</span> Pathfinder = <span class="global">require</span> (<span class="string">"jumper.pathfinder"</span>)

<span class="keyword">local</span> map = {
  {<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>},
  {<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>},
  {<span class="number">0</span>,<span class="number">1</span>,<span class="number">1</span>,<span class="number">1</span>,<span class="number">1</span>,<span class="number">0</span>},
  {<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>},
  {<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>},
}

<span class="keyword">local</span> walkable = <span class="number">0</span>
<span class="keyword">local</span> grid = Grid(map)
<span class="keyword">local</span> myFinder = Pathfinder(grid, <span class="string">'ASTAR'</span>, walkable)

<span class="comment">-- Use Euclidian heuristic to evaluate distance
</span>myFinder:setHeuristic(<span class="string">'EUCLIDIAN'</span>)
myFinder:setHeuristic(<span class="string">'DIAGONAL'</span>)
myFinder:setHeuristic(<span class="string">'MANHATTAN'</span>)

<span class="comment">-- Custom
</span><span class="keyword">local</span> h = <span class="keyword">function</span>(nodeA, nodeB)
	<span class="keyword">return</span> (<span class="number">0.1</span> * (<span class="global">math</span>.abs(nodeA:getX() - nodeB:getX()))
	      + <span class="number">0.9</span> * (<span class="global">math</span>.abs(nodeA:getY() - nodeB:getY())))
<span class="keyword">end</span>
myFinder:setHeuristic(h)

<span class="keyword">local</span> p = myFinder:getPath(<span class="number">1</span>,<span class="number">1</span>, <span class="number">6</span>,<span class="number">5</span>)
<span class="keyword">for</span> node, count <span class="keyword">in</span> p:nodes() <span class="keyword">do</span>
  <span class="global">print</span>((<span class="string">'%d. Node(%d,%d)'</span>):format(count, node:getX(), node:getY()))
<span class="keyword">end</span>
<span class="global">print</span>((<span class="string">'Path length: %.2f'</span>):format(p:getLength()))

<span class="comment">-- etc ...
</span></pre>


</div> <!-- id="content" -->
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.2</a></i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
</html>
